#!/usr/bin/php
<?php
$controller_name = "index";
$actions = array('index');

//----------------------------------------setting up controller
$file = "standard_templates/controller";
//$dir =  dirname(dirname(dirname(__FILE__)));
//$newfile = $dir . "/{$controller_name}.php";
$newfile = realpath ("../../{$controller_name}.php");
//echo $newfile;
mycopyfile($file, $newfile);

//----------------------------------------setting up helpers
$file = "standard_templates/helper";
$newfile = realpath ("../helpers/{$controller_name}_helper.php");
mycopyfile($file, $newfile);


//----------------------------------------setting up layouts
$file = "standard_templates/layout";
$newfile = realpath ("../views/layouts/{$controller_name}_layout.php");
mycopyfile($file, $newfile);

//----------------------------------------setting up views
$newmkdir = realpath ("../views/{$controller_name}");
mkdir($newmkdir);
setperms($newmkdir);

//----------------------------------------setting up actions
$file = "standard_templates/action";
foreach ($actions as $action) {
	$newfile = realpath ("../views/{$controller_name}/{$action}.php");
	mycopyfile($file, $newfile);
}

//----------------------------------------setting up stylesheets
$newmkdir = realpath ("../../stylesheets/{$controller_name}");
mkdir($newmkdir);
setperms($newmkdir);
//------------------------setting up css sheets for actions
$file = "standard_templates/css";
foreach ($actions as $action) {
	$newfile = realpath ("../../stylesheets/{$controller_name}/{$action}.css");
	mycopyfile($file, $newfile);
}



//----------------------------------------setting up models....leaving for now

//----------------------------------------setting up javascripts










//-----------------------functions
function setperms($newfile) {
//$thisfileowner = fileowner  ( "generator_script"  );
$thisfileowner = fileowner  ( __FILE__  );
chown  ( $newfile  , $thisfileowner  );
//$thisfilegrp = filegroup  ( "generator_script"  );
$thisfilegrp = filegroup  ( __FILE__  );
chgrp  ( $newfile  , $thisfilegrp  );
}

function mycopyfile($file, $newfile) {
	if (!copy($file, $newfile)) { 
		echo "failed to copy $file...\n"; 
	} else {
		setperms($newfile);
		//echo realpath ( "../generator_script"  );
	}
}

?>
